|
|
|
|
|
|
|
Basic. When you create a unique Workspace object, you isolate all your database operations into a single session. You can then group a set of database transactions into a single session to improve database integrity and security. |
|
|
|
|
|
|
|
|
Let's add a new command button to the project that will create a new Workspace object. Set the button's Name property to cmdNewWorkSpace and set its Caption property to &New WS. Add the code in Listing 9.7 into the cmdNewWorkSpace_Click code window. |
|
|
|
|
|
|
|
|
Listing 9.7. Coding the cmdNewWorkSpace_Click event. |
|
|
|
|
|
|
|
|
Private Sub cmdNewWorkSpace_Click()
'
' create a new workspace
'
Dim ws As Workspace
Dim strWSName As String
Dim strWSUser As String
Dim strWSPassword As String
'
' init vars
strWSName = "ws" & App.EXEName
strWSUser = "admin"
strWSPassword = ""
'
' create it
Set ws = DBEngine.CreateWorkspace(strWSName, strWSUser, strWSPassword)
'
' append to collection
DBEngine.Workspaces.Append ws
'
' show them all
cmdWorkspaces_Click
'
End Sub |
|
|
|
|
|
|
|
|
The code in Listing 9.7 establishes local variables and then initializes them to the correct values. Notice that you can use any unique name you like for the Workspace object, but you must use valid User and Password parameters. These values must already exist in the system security file or as the default values if Microsoft Access security is not active. Because you do not use Microsoft Access security here, this example used the default admin user name and empty password. |
|
|
|
|
|
|
|
|
You used the CreateWorkspace method to create a valid Workspace object. You can now use this object throughout your program. As an option, you can add the new object to the Workspaces collection, by using the Append method. After adding the new object, you can force Visual Basic to display the Workspaces collection to see your results. |
|
|
|
|
|